/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package inventorymanagement;


import Entity.SalesChart;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.util.ArrayList;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
//import org.jfree.ui.ApplicationFrame;
//import org.jfree.ui.RefineryUtilities;

/**
 *
 * @author Home
 */
//ApplicationFrame
public class NewClass2 extends javax.swing.JInternalFrame {
    public NewClass2(String title, ArrayList<Entity.SalesChart> a)
    {
        super(title);
        CategoryDataset dataset = createDataset(a);
        JFreeChart chart = createChart(dataset);
        ChartPanel chartPanel = new ChartPanel(chart, false);
        chartPanel.setPreferredSize(new Dimension(500, 270));
        setContentPane(chartPanel);
    }


    private static CategoryDataset createDataset(ArrayList<Entity.SalesChart> sc)
    {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        for (SalesChart salesChart : sc) {
            String date = salesChart.getDate().substring(0, 10);
            dataset.addValue(salesChart.getQuantity(), salesChart.getItemName(), date);
        }

        return dataset;
    }


    private static JFreeChart createChart(CategoryDataset dataset)
    {
        //create the chart...
        JFreeChart chart = ChartFactory.createBarChart(
                "Bar Chart",
                "Item Name",
                "Unit",
                dataset,
                PlotOrientation.VERTICAL,
                true,
                true,
                false);

        //setBaxkground color for the chart..
        chart.setBackgroundPaint(Color.white);

        //get a reference to the plot for further customisation....
        CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.white);

        //set the range axis to display integers only...
        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        //disable bar outlines....
        BarRenderer renderer = (BarRenderer) plot.getRenderer();
        renderer.setDrawBarOutline(false);

        //setup gradient paints for series.....
        GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.yellow,
                0.0f, 0.0f, new Color(0, 0, 64));

        renderer.setSeriesPaint(0, gp);

        CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(
                Math.PI/6.0));

        return chart;
    }


//    public static void main(String[] args) {
//        ArrayList<objecta> arr = new ArrayList<objecta>();
//        arr.add(new objecta(1, "hang1", "vai1/1"));
//        arr.add(new objecta(20, "hang1", "vai2"));
//        arr.add(new objecta(5, "hang1", "vai3"));
//        arr.add(new objecta(7, "hang1", "vai4"));
//        arr.add(new objecta(3, "hang1", "vai5"));
//        arr.add(new objecta(8, "hang1", "vai6"));
//        arr.add(new objecta(14, "hang1", "vai7"));
//        arr.add(new objecta(17, "hang1", "vai8"));
//        arr.add(new objecta(2, "hang1", "vai9"));
//        arr.add(new objecta(6, "hang1", "vai10"));
//        arr.add(new objecta(7, "hang1", "vai11"));
//        arr.add(new objecta(8, "hang1", "vai12"));
//        arr.add(new objecta(9, "hang1", "vai13"));
//        arr.add(new objecta(10, "hang1", "vai14"));
//        arr.add(new objecta(21, "hang1", "vai15"));
        
//        NewClass2 demo = new NewClass2("Bar Chart demo", arr);
//        demo.pack();
//
//        RefineryUtilities.centerFrameOnScreen(demo);
//        demo.setVisible(true);
//    }
    
}
